package com.wang.arrayList;

import com.wang.collection.Student;

import java.util.ArrayList;

/**
 * arrayList的使用
 * 存储结构:数组 查找遍历速度快, 增删速度慢
 */
public class arrayListDemo1 {
    public static void main(String[] args) {
        ArrayList<Student> arrayList = new ArrayList<>();
        Student s1 = new Student("a",1),
                s2 = new Student("b",2),
                s3 = new Student("c",3);
        //1.添加
        arrayList.add(s1);
        arrayList.add(s2);
        arrayList.add(s3);
        System.out.println(arrayList.size());
        System.out.println(arrayList.toString());
        //2.删除
        arrayList.remove(0);//或者通过s1变量删除..new一个对象时删除不了的
        //3.遍历 与list相同
        //1.普通的前向iterator
        //2.双向的增强版listIterator
        //查找
        System.out.println("查找");
        System.out.println(arrayList.indexOf(s2));
        System.out.println(arrayList.get(0));
    }
}
